package com.atguigu.realtime.func;

import com.atguigu.realtime.utils.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

/**
 * @author: 洛尘
 * @since: 2023-10-11 11:19
 * @description: 自定义函数 UDTF
 **/
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class KeywordUDTF extends TableFunction<Row> {
    public void eval(String str) {
        for (String keyword : KeywordUtil.analyze(str)) {
            // use collect(...) to emit a row
            collect(Row.of(keyword));
        }
    }
}